package servlet;

import dao.BookDao;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "DeleteBookServlet", value = "/DeleteBookServlet")
public class DeleteBookServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        int id = Integer.parseInt(request.getParameter("id"));
        BookDao bd = new BookDao();
        boolean isDelete = bd.deleteBook(id);
        if (isDelete) {
            request.getRequestDispatcher("/ListBookServlet").forward(request, response);
        } else {
            request.setAttribute("insertMsg", "删除图书失败");
//            request.getRequestDispatcher("/add.jsp").forward(request, response);
        }

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
